//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import timeDisplay from './timeDisplay'
import clockHours from './clockHours'
import clockMinutes from './clockMinutes'
import flatButton from '../flatButton'
export default {
props: {
autoOk: {
type: Boolean,
default: false
},
format: {
type: String,
default: 'ampm',
validator (val) {
return ['ampm', '24hr'].indexOf(val) !== -1
}
},
initialTime: {
type: Date,
default () {
return new Date()
}
},
okLabel: {
type: String,
default: '确定'
},
cancelLabel: {
type: String,
default: '取消'
},
landscape: {
type: Boolean,
default: false
}
},
data () {
return {
selectedTime: this.initialTime,
mode: 'hour'
}
},
methods: {
getAffix () {
if (this.format !== 'ampm') return ''
const hours = this.selectedTime.getHours()
if (hours < 12) {
return 'am'
}
return 'pm'
},
handleSelectAffix (affix) {
if (affix === this.getAffix()) return
const hours = this.selectedTime.getHours()
if (affix === 'am') {
this.handleChangeHours(hours - 12, affix)
return
}
this.handleChangeHours(hours + 12, affix)
},
handleChangeHours (hours, finished) {
const time = new Date(this.selectedTime)
let affix
if (typeof finished === 'string') {
affix = finished
finished = undefined
}
if (!affix) {
affix = this.getAffix()
}
if (affix === 'pm' && hours < 12) {
hours += 12
}
time.setHours(hours)
this.selectedTime = time
if (finished) {
setTimeout(() => {
this.mode = 'minute'
this.$emit('changeHours', time)
}, 100)
}
},
handleChangeMinutes (minutes) {
const time = new Date(this.selectedTime)
time.setMinutes(minutes)
this.selectedTime = time
setTimeout(() => {
this.$emit('changeMinutes', time)
if (this.autoOk) this.accept()
}, 0)
},
accept () {
this.$emit('accept', this.selectedTime)
},
dismiss () {
this.$emit('dismiss')
}
},
watch: {
initialTime (val) {
this.selectedTime = val
}
},
components: {
'time-display': timeDisplay,
'clock-hours': clockHours,
'clock-minutes': clockMinutes,
'flat-button': flatButton
}
}
|